package com.gec.wiki.controller;


import com.gec.wiki.req.UserLoginReq;
import com.gec.wiki.req.UserQueryReq;
import com.gec.wiki.req.UserResetPasswordReq;
import com.gec.wiki.req.UserSaveReq;
import com.gec.wiki.resp.CommonResp;
import com.gec.wiki.resp.PageResp;
import com.gec.wiki.resp.UserLoginResp;
import com.gec.wiki.resp.UserQueryResp;
import com.gec.wiki.service.IUserService;
import com.gec.wiki.utils.CopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2023-12-14
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/getUserListByPage")
    public CommonResp getUserListByPage(UserQueryReq req){
        PageResp<UserQueryResp> userListByPage = userService.getUserListByPage(req);
        CommonResp<PageResp<UserQueryResp>> resp = new CommonResp<>();
        resp.setContent(userListByPage);
        return resp;
    }

    @RequestMapping("/save")
    public CommonResp save(@Valid @RequestBody UserSaveReq req){
        userService.saveUser(req);
        CommonResp commonResp = new CommonResp<>();
        return commonResp;
    }
//    @GetMapping("/remove")
//    public CommonResp remove(int id){
//        userService.removeById(id);
//        CommonResp<Object> resp = new CommonResp<>();
//        return resp;
//    }
    @RequestMapping("/userLogin")
    public CommonResp userLogin(@Valid @RequestBody UserLoginReq req){
        CommonResp resp = new CommonResp<>();
        UserLoginResp userLoginResp = userService.userLogin(req);
        resp.setContent(userLoginResp);
        return resp;
    }
//    @RequestMapping("/resetPassword")
//    public CommonResp resetPassword(@Valid @RequestBody UserResetPasswordReq req){
//
//
//        userService.resetPassword(req);
//        CommonResp resp = new CommonResp<>();
//        return resp;
//    }
}
